import { Component,OnInit, Input } from '@angular/core';
import { Router } from '@angular/router';
import { HttpClient } from '@angular/common/http';
import {Headers,RequestOptions,URLSearchParams} from "@angular/http";
import {ActivatedRoute} from "@angular/router";
import { Location } from '@angular/common';
import {Pport} from "./pmodule/pport";
import {Ppoint} from "./pmodule/ppoint";
import {Pmonitor} from "./pmodule/pmonitor";
import {Pequi} from "./pmodule/pequi";
import {Port} from "./pmodule/port";
import {Monitor} from "./pmodule/monitor";
import {Point} from "./pmodule/point";
import {Equi} from "./pmodule/equi";
import {Acq} from "./pmodule/acq";
import {Pacq} from "./pmodule/pacq";
import {PointService} from "./pservice/point.service";
import {PagerService} from "../../pagination/pager.service";
import {UtilService} from "./util.service";
import {DatePipe} from "@angular/common";
@Component({
  selector: 'app-point',
  templateUrl: './point.component.html',
  styleUrls: ['./point.component.css']
})
export class PointComponent implements OnInit {
  private list: Array<any>;
  private info: Array<any>;
  lookInfo: Pport = new Port("", "", "", "", "", "","", "", "");//查看排放口详情信息
  monitorInfo: Pmonitor = new Monitor("", "", "", "");//查看监控点详情信息
  EquipInfo: Pequi = new Equi("", "", "","");//查看数采仪设备
  PointInfo: Ppoint = new Ppoint("", "", "", "", "", "", "", "");//查看污染物
  acqListLook: Pacq = new Acq("", "", "", "", "", "", "","", "", "", "", "", "", "","", "", "", "", "", "", "", "");//查看数采仪详情
  dataList: any;
  portList:any;//排放口list
  monitorList:any;//监控点list
  dataAcqList:any;//数采仪信息关联
  equipList:any;//数采仪备注关联
  codeList:any;
  pchecked: boolean = false;
  isRemove: boolean = true;//点击移除删除弹框
  errorMessage:string;//错误信息
  pollutname: '';
  addName: '';
  deleteId: '';//删除id
  urldata: any;
  addInfo:Pport;//添加传参
  arealist:'';
  monitorlist:'';
  portlist:'';
  equipmentlist:'';
  DataAcqList:'';
  queryEquipmentList:'';
  queryAcqEquipment:'';
  equipmentId:'';
  dataLookList:'';
  equipmentName:'';
  equipmentNameId:'';
  dataCodeList:'';
  b:'';
  addportName:'';
  addaddportCode:'';
  addlongitude:'';
  addlatitude:'';
  addmonitorType:'';
  addmonitorName:'';
  addportId:'';
  addacquistionId:'';
  addmonitorId:'';
  addacquistionId1:'';
  addequipmentId1:'';
  dateStr:string;//时间格式化
  constructor(private http: HttpClient,
              location: Location,
              private route: ActivatedRoute,
              private pointService: PointService,
              private pagerService: PagerService,
              private utilService: UtilService,
              private datePipe: DatePipe) {
  }
  //关联监控点
  getMonitor() {
    this.pointService.getMonitor(this.urldata)
      .subscribe(
        data => {
          this.monitorlist=data;
        });
  }
  //关联排放口
  getPort() {
    this.pointService.getPort(this.urldata)
      .subscribe(
        data => {
          this.portlist=data;
        });
  }
  //查看数采仪关联信息详情
  acqMessageLook(id) {
    this.pointService.getAcqList(id)
      .subscribe(
        data => {
          this.acqListLook=data;
          this.dateStr =this.datePipe.transform(this.acqListLook['restartTime'], 'yyyy-MM-dd HH:mm:ss');
        });
  }

  //设备名称
  getEquipment() {
    this.pointService.getEquipment()
      .subscribe(
        data => {
          this.equipmentlist=data;
        });
  }
  //行政区列表
  areaList() {
    this.pointService.getArea()
      .subscribe(
        data => {
          this.arealist=data;
        });
  }
  //数采仪
  getDataAcqList(){
    this.pointService.getDataAcqList(this.urldata)
      .subscribe(
        data => {
          this.DataAcqList=data;
        });
  }
  getqueryEquipmentList(){
    this.pointService.getqueryEquipmentList()
      .subscribe(
        data => {
          this.queryEquipmentList=data;
        });
  }
  //列表页
  getLists() {
    this.pointService.getLists(this.urldata).subscribe(data => {
        this.dataList = data;
        this.portList=data.portList;
        this.monitorList=data.monitorList;
        this.dataAcqList=data.dataAcqList;
        this.equipList=data.equipList;
        this.codeList=data.codeList;
      },
      error => this.errorMessage = <any>error
    );
  }
//查看and编辑--排放口
  userMessage(polluter: any) {
    let lookObj = {};
    Object.assign(lookObj, polluter);
    this.lookInfo = lookObj;
  }
  //排放口编辑
  doEditPort(editInfo:any,valid:boolean){
    if(valid) {
      this.pointService.editExhibit(editInfo).subscribe(
        data => {
          if (data.resultCode == 0) {
            $("#updateModal").modal('hide');
            $("#update").modal('show');
            this.getLists();
            this.getPort();
          } else {
            this.errorMessage = "编辑失败！";
            $("#error").modal('show');
          }
        });
    }
  }
  //排放口删除
  delete(pollutId) {
    this.deleteId = pollutId;
  }
  deletePollut(id) {
    this.pointService.deletePollut(id)
      .subscribe(
        data => {
          if(data.resultCode==0){
            $("#delete").modal('show');
            this.getLists();
            this.getPort();
          }else if(data.resultCode==1){
            this.errorMessage = "删除失败！";
            $("#error").modal('show');
          }
        });
  }
  //排放口添加
  doAddPort(addInfo: any,valid:boolean) {
    if(valid) {
      this.pointService.createPollut(addInfo).subscribe(
        data => {
          if (data.resultCode == '0') {
            $("#addModal").modal('hide');
            $('.clear-input').val('');
            this.addportName='';
            this.addaddportCode='';
            this.addlongitude='';
            this.addlatitude='';
            $("#add").modal('show');
            this.getLists();
            this.getPort();
          } else {
            this.errorMessage = "添加失败！";
            $("#error").modal('show');
          }
        });
    }
  }
//查看and编辑--监控点
  monitorMessage(polluter: any) {
    let lookObj = {};
    Object.assign(lookObj, polluter);
    this.monitorInfo = lookObj;
  }
  //监控点编辑
  doEditmonitor(editInfo:any,valid:boolean) {
    if (valid) {
      this.pointService.editMonitor(editInfo).subscribe(
        data => {
          if (data.resultCode == 0) {
            $("#updateModal1").modal('hide');
            $("#update").modal('show');
            this.getLists();
            this.getMonitor();
          } else {
            this.errorMessage = "编辑失败！";
            $("#error").modal('show');
          }
        });
    }
  }
  //监控点删除
  deleteMonitor(pollutId) {
    this.deleteId = pollutId;
  }
  deletemonitor(id) {
    this.pointService.deleteMonitor(id)
      .subscribe(
        data => {
          if(data.resultCode==0){
            $("#delete").modal('show');
            this.getLists();
            this.getMonitor();
          }else if(data.resultCode==1){
            this.errorMessage = "删除失败！";
            $("#error").modal('show');
          }
        });
  }
  //监控点添加
  doAddmonitor(addInfo: any,valid:boolean) {
    if (valid) {
      this.pointService.createMonitor(addInfo).subscribe(
        data => {
          if(data.resultCode=='0'){
            $("#addModal1").modal('hide');
            $('.clear-input').val('');
            this.addmonitorType='';
            this.addmonitorName='';
            this.addportId='';
            $("#add").modal('show');
            this.getLists();
            this.getMonitor();
            scrollTo(0,0);
          }else {
            this.errorMessage = "添加失败！";
            $("#error").modal('show');
          }
        });
    }
  }
//查看and编辑--数采仪关联信息
  equiMessage(polluter: any) {
    let lookObj = {};
    Object.assign(lookObj, polluter);
    this.EquipInfo = lookObj;
  }
  //数采仪关联信息编辑
  doEditequia(editInfo:any,valid:boolean){
    if(valid) {
      let obj = {
        "pointAcquipmentDO":
          {
            "id":editInfo.id,
            "acquistionId":editInfo.acquistionId,
            "monitorId": editInfo.monitorId,
            "versionNumber": editInfo.versionNumber,
            "manufacturer": editInfo.manufacturer,
            "portIp": editInfo.portIp,
            "remark": editInfo.remark
          },
        "dataAcqDO": {
          "dataAcquistionId":editInfo.dataAcquistionId,
          "mn": editInfo.mn,
          "password": editInfo.password,
          "stType": editInfo.stType,
          "restartTime":$("#startEndTime").val(),
          "overTimes":editInfo.overTimes,
          "sendCount": editInfo.sendCount,
          "rtdInterval": editInfo.rtdInterval,
          "minInterval": editInfo.minInterval,
          "saveInterval": editInfo.saveInterval,
          "realFlag": editInfo.realFlag,
          "equipmentFlag": editInfo.equipmentFlag,
          "startFlag": editInfo.startFlag,
          "receiveFlag": editInfo.receiveFlag,
          "showFlag": editInfo.showFlag,
          "forwardFlag": editInfo.forwardFlag,
          "validSwitch": editInfo.validSwitch
        }
      };
      let dataObj = JSON.stringify(obj)
      this.pointService.editEqui(dataObj).subscribe(
        data => {
          if(data.resultCode==0) {
            $("#updateModal2").modal('hide');
            $("#update").modal('show');
            this.getLists();
            this.getDataAcqList();
          }else {
            this.errorMessage = "编辑失败！";
            $("#error").modal('show');
          }});
    }
  }
  //数采仪关联信息删除
  deleteEqui(pollutId) {
    this.deleteId = pollutId;
  }
  deleteequi(id) {
    this.pointService.deleteEqui(id)
      .subscribe(
        data => {
          if(data.resultCode==0){
            $("#delete").modal('show');
            this.getLists();
            this.getDataAcqList();
          }else if(data.resultCode==1){
            this.errorMessage = "删除失败！";
            $("#error").modal('show');
          }
        });
  }
  //数采仪关联信息添加
  doAddequi(addInfo: any,valid:boolean) {
    if(valid) {
      let obj = {
        "pointAcquipmentDO":
          {
            "acquistionId": addInfo.acquistionId,
            "monitorId": addInfo.monitorId,
            "versionNumber": addInfo.versionNumber,
            "manufacturer": addInfo.manufacturer,
            "portIp": addInfo.portIp,
            "remark": addInfo.remark
          },
        "dataAcqDO": {
          "mn": addInfo.mn,
          "password": addInfo.password,
          "stType": addInfo.stType,
          "restartTime": $("#startEndTimestart").val(),
          "overTimes": addInfo.overTimes,
          "sendCount": addInfo.sendCount,
          "rtdInterval": addInfo.rtdInterval,
          "minInterval": addInfo.minInterval,
          "saveInterval": addInfo.saveInterval,
          "realFlag": addInfo.realFlag,
          "equipmentFlag": addInfo.equipmentFlag,
          "startFlag": addInfo.startFlag,
          "receiveFlag": addInfo.receiveFlag,
          "showFlag": addInfo.showFlag,
          "forwardFlag": addInfo.forwardFlag,
          "validSwitch": addInfo.validSwitch
        }
      };
      //a.push(obj);
      let dataObj = JSON.stringify(obj);
      this.pointService.createEqui(dataObj).subscribe(
        data => {
          if(data.resultCode=='0'){
            $("#addModal2").modal('hide');
            $('.clear-input').val('');
            this.addacquistionId='';
            this.addmonitorId='';
            $("#add").modal('show');
            this.getLists();
            this.getDataAcqList();
            scrollTo(0,0);
          }else {
            this.errorMessage = "添加失败！";
            $("#error").modal('show');
          }

        });
    }
  }
//查看and编辑--数采仪设备关联
  equimentMessage(polluter: any) {
    let lookObj = {};
    Object.assign(lookObj, polluter);
    this.EquipInfo = lookObj;
  }
  //数采仪设备关联编辑
  doEditequiment(editInfo:any,valid:boolean){
    if(valid) {
      this.pointService.editEquiment(editInfo).subscribe(
        data => {
          if(data.resultCode==0) {
            $("#updateModal4").modal('hide');
            $("#update").modal('show');
            this.getLists();
            this.getqueryEquipmentList();
            this.queryAcqEquipmentList();
          }else {
            this.errorMessage = "编辑失败！";
            $("#error").modal('show');
          }});
    }
  }
  //数采仪设备关联删除
  deleteEquiment(pollutId) {
    this.deleteId = pollutId;
  }
  deletement(id) {
    this.pointService.deleteEquiment(id)
      .subscribe(
        data => {
          if(data.resultCode==0){
            $("#delete").modal('show');
            this.getLists();
            this.getqueryEquipmentList();
            this.queryAcqEquipmentList();
          }else if(data.resultCode==1){
            this.errorMessage = "删除失败！";
            $("#error").modal('show');
          }
        });
  }
  //数采仪设备关联添加
  doAddEquiment(addInfo: any,valid:boolean) {
    if(valid) {
      this.pointService.createEquiment(addInfo).subscribe(
        data => {
          if(data.resultCode=='0'){
            $("#addModal4").modal('hide');
            $('.clear-input').val('');
            this.addacquistionId1='';
            this.addequipmentId1='';
            $("#addModal").modal('hide');
            this.getLists();
            this.getqueryEquipmentList();
            this.queryAcqEquipmentList();
            scrollTo(0,0);
          }else {
            this.errorMessage = "添加失败！";
            $("#error").modal('show');
          }

        });
    }
  }

//查看污染物关联信息
  pointMessage(name,id) {
    this.equipmentName=name;
    this.equipmentNameId=id;
    this.pointService.lookEquiPollutant(id)
      .subscribe(
        data => {
          this.dataLookList=data;
        });
  }
  getCodeListTwo(){
    this.getCodeList(this.b);
  }
  getCodeList(queryObj){
    this.pointService.getCodeList(queryObj)
      .subscribe(
        data => {
          this.dataCodeList=data;
        });

  }
  /**
   * 设备选择事件方法
   * */
  getChangeSlectedId(selectid,act,boxid){
    //获取对应设备的检测因子数据
    this.pointService.getCodeList(selectid)
      .subscribe(
        data => {
          this.dataCodeList=data;
          let codeData=$('#'+boxid);
          if(codeData.html()!=""){
            let ddlSelect=codeData.find('select');
            if(act=='add'){
              ddlSelect=codeData.find('select:last');
            }
            let objList=this.dataCodeList;
            //遍历下拉框赋值
            $.each(ddlSelect,function (item,i) {
              let obj=$(this);
              obj.empty();
              let html='';
              for(let i=0; i<objList.length;i++){
                html+='<option value='+objList[i]['code']+'>'+objList[i]['pollutantName']+'</option>';
              }
              obj.append(html);
            });
          }
        });
  }
  /**
   * 编辑污染物关联信息
   * **/
  pointMessageedit(name,id){
    this.equipmentName=name;
    this.equipmentNameId=id;
    let codeData=$('#code-boxedit');
    codeData.html('');
    //this.getCodeList(id);
    this.pointService.getCodeList(id)
      .subscribe(
        data => {
          this.dataCodeList=data;

          this.pointService.lookEquiPollutant(id)
            .subscribe(
              datajson => {
                this.dataLookList=datajson;
                let num = this.dataLookList.length;
                for(let j=0; j<num;j++){
                  let dataEdit=this.dataLookList[j];
                  this.addCodeBoxHtml(codeData,this.dataCodeList,dataEdit);
                }
              });
        });
  }
  deleteData(){
    if(this.equipmentNameId !=undefined){
      this.pointService.deletePoint(this.equipmentNameId) .subscribe(
        data => {
        });
    }
    $(this).parent().remove();
  }
  //污染物编辑
  doEditpoint(equipmentId){
    let arrayObj = new Array();
    let codebox = $("#code-boxedit .first-line");
    $.each(codebox, function (item,i) {
      let obj = $(this).find("input");
      let objselect = $(this).find("select");
      let pollutantCode = objselect.eq(0).val(); //检测因子
      let warnMin = obj.eq(0).val();//预警最小值
      let warnMax = obj.eq(1).val();//预警最大值
      let manualMin = obj.eq(2).val();//人工预警最小值
      let manualMax = obj.eq(3).val();//人工预警最大值
      let rangeMax = obj.eq(4).val();//量程上限
      let rangeMin = obj.eq(5).val();//量程下限
      let startTime = obj.eq(6).val();//采样起始时间
      let samplePeriod = obj.eq(7).val();//采样周期(h)
      let outTime = obj.eq(8).val();//出样时间
      let id = obj.eq(9).val();//id
      let objson = { "id": "" + id + "","equipmentId": "" + equipmentId + "","pollutantCode": "" + pollutantCode + "", "warnMin": "" + warnMin + "", "warnMax": "" + warnMax + "", "manualMin": "" + manualMin + "", "manualMax": "" + manualMax + "", "rangeMax": "" + rangeMax + "", "rangeMin": "" + rangeMin + "", "startTime": "" + startTime + "", "samplePeriod": "" + samplePeriod + "", "outTime": "" + outTime + "" };
      arrayObj.push(objson);
    });
    let dataObj = JSON.stringify(arrayObj);
    this.pointService.editPoint(dataObj).subscribe(
      data => {
        if(data.resultCode=='0'){
          $("#updateModal3").modal('hide');
          $("#update").modal('show');
          this.getLists();
        }else {
          this.errorMessage = "编辑失败！";
          $("#error").modal('show');
        }

      });
  }
  //删除
  deletePoint(pollutId) {
    this.deleteId = pollutId;
  }

  deletepoint(id) {
    this.pointService.deleteEquiPollutant(id)
      .subscribe(
        data => {
          if(data.resultCode==0) {
            $("#delete").modal('show');
            this.getLists();
          }else {
            this.errorMessage = "删除失败！";
            $("#error").modal('show');
          }
        });
  }
  nullValue(value){
    if(value==undefined) {
      value = '';
    }
    return value;
  }
  addCodeBoxHtml(codeBox,ddlCodeList,data){
    let codeData=codeBox;
    let html='';
    html+=' <div class="form-group first-line clearfix col-md-12">';
    if(codeBox=='code-box' || data==null) {
      html += '<div class="delete-data" click="deleteData()"><img src="assets/img/deleteDoat.png" >删除</div>';
    }
    html+='<div class="row clearfix">';
    html+='<label class="col-sm-1 control-label">检测因子：</label> ';
    html+='<div class="col-sm-3">';
    html+='<select class="form-control selectStyle " ngModel  name="pollutantCode" required>';
    html+='<option value="">请选择</option>';
    if(ddlCodeList!=null && ddlCodeList.length>0){
    for(let i=0; i<ddlCodeList.length;i++){
       html+='<option value='+ddlCodeList[i]['code']+'>'+ddlCodeList[i]['pollutantName']+'</option>';
    }}
    html+='</select>';
    html+='</div> ';
    html+='<label class="col-sm-1 control-label">预警最小值：</label>';
    html+='<div class="col-sm-3">';
    html+='<input type="text" class="form-control" placeholder="请输入" name="warnMin" value=""  ngModel>';
    html+='</div>';
    html+='</div>';
    html+='<div class="row clearfix">';
    html+='<label class="col-sm-1 control-label">预警最大值：</label>';
    html+='<div class="col-sm-3">';
    html+='<input type="text" class="form-control" placeholder="请输入" name="warnMax"  value=""  ngModel>';
    html+='</div>';
    html+='<label class="col-sm-1 control-label">人工预警最小值：</label>';
    html+='<div class="col-sm-3">';
    html+='<input type="text" class="form-control" placeholder="请输入" name="manualMin"  value=""  ngModel>';
    html+='</div>';
    html+='</div>';
    html+='<div class="row clearfix">';
    html+='<label class="col-sm-1 control-label">人工预警最大值：</label>';
    html+='<div class="col-sm-3">';
    html+='<input type="text" class="form-control" placeholder="请输入" name="manualMax"  value=""  ngModel>';
    html+='</div>';
    html+='<label class="col-sm-1 control-label">量程上限：</label>';
    html+='<div class="col-sm-3">';
    html+='<input type="text" class="form-control" placeholder="请输入" name="rangeMax"  value=""  ngModel>';
    html+='</div>';
    html+='</div>';
    html+='<div class="row clearfix">';
    html+='<label class="col-sm-1 control-label">量程下限：</label>';
    html+='<div class="col-sm-3">';
    html+='<input type="text" class="form-control" placeholder="请输入" name="rangeMin"  value=""  ngModel>';
    html+='</div>';
    html+='<label class="col-sm-1 control-label">采样起始时间：</label>';
    html+='<div class="col-sm-3">';
    html+='<input type="text" class="form-control" placeholder="hhmmss" name="startTime"  value=""  ngModel>';
    html+='</div>';
    html+='</div>';
    html+='<div class="row clearfix">';
    html+='<label class="col-sm-1 control-label">采样周期(h)：</label>';
    html+='<div class="col-sm-3">';
    html+='<input type="text" class="form-control" placeholder="取值0~24" name="samplePeriod"  value=""  ngModel>';
    html+='</div>';
    html+='<label class="col-sm-1 control-label">出样时间(min)：</label>';
    html+='<div class="col-sm-3">';
    html+='<input type="text" class="form-control" placeholder="取值0~120" name="outTime"  value=""  ngModel>';
    html+='<input type="hidden" class="form-control" placeholder="请输入" name="id"  value="">';
    html+='</div>';
    html+='</div>';
    html+= '</div>';
    codeData.append(html);
    let deleteData=$('.delete-data');
    deleteData.click(function () {
      $(this).parent().remove();
    });
    if(data!=null){
      let obj=codeData.find('.form-group').last();
      //let objselect=codeData.find('.form-group').last().find('select');
      let pollutantCode =this.nullValue(data['pollutantName']);// objselect.eq(0).val(); //检测因子
      let warnMin = this.nullValue(data['warnMin']);//预警最小值
      let warnMax = this.nullValue(data['warnMax']);//预警最大值
      let manualMin = this.nullValue(data['manualMin']);//人工预警最小值
      let manualMax = this.nullValue(data['manualMax']);//人工预警最大值
      let rangeMax =this.nullValue(data['rangeMax']);//量程上限
      let rangeMin = this.nullValue(data['rangeMin']);//量程下限
      let startTime = this.nullValue(data['startTime']);//采样起始时间
      let samplePeriod = this.nullValue(data['samplePeriod']);//采样周期(h)
      let outTime =this.nullValue(data['outTime']);//出样时间
      let id =this.nullValue(data['quipPollId']);//编辑传id
      //检测因子
      obj.find("select[name='pollutantCode']").find("option:contains('"+pollutantCode+"')").attr("selected",true);
      //预警最小值
      obj.find("input[name='warnMin']").val(warnMin);
      //预警最大值
      obj.find("input[name='warnMax']").val(warnMax);
      //人工预警最小值
      obj.find("input[name='manualMin']").val(manualMin);
      //人工预警最大值
      obj.find("input[name='manualMax']").val(manualMax);
      //量程上限
      obj.find("input[name='rangeMax']").val(rangeMax);
      //量程下限
      obj.find("input[name='rangeMin']").val(rangeMin);
      //采样起始时间
      obj.find("input[name='startTime']").val(startTime);
      //采样周期(h)
      obj.find("input[name='samplePeriod']").val(samplePeriod);
      //出样时间(min)
      obj.find("input[name='outTime']").val(outTime);
      //编辑传id
      obj.find("input[name='id']").val(id);
    }


  }

 /**
 * 添加
 * **/
  addPortExt(codebox){
  let codeData=$('#'+codebox);
  this.addCodeBoxHtml(codeData,null,null);
  let eid=this.equipmentId;
  if(codebox=='code-boxedit'){
    eid=this.equipmentNameId;
  }
  //
  this.getChangeSlectedId(eid,'add',codebox);
  }
//添加因子
  addPort(){
    let codeData=$('#code-box');
    let html='';
    html+=' <div class="form-group first-line clearfix col-md-12">';
    html+='<div class="delete-data" click="deleteData()"><img src="assets/img/deleteDoat.png" >删除</div>';
    html+='<div class="row clearfix">';
    html+='<label class="col-sm-1 control-label">检测因子：</label> ';
    html+='<div class="col-sm-3">';
    html+='<select class="form-control selectStyle " ngModel  name="pollutantCode" required>';
    html+='<option value="">请选择</option>';
    for(let i=0; i<this.dataCodeList.length;i++){
      html+='<option value='+this.dataCodeList[i]['code']+'>'+this.dataCodeList[i]['pollutantName']+'</option>';
    }
    html+='</select>';
    html+='</div> ';
    html+='<label class="col-sm-1 control-label">预警最小值：</label>';
    html+='<div class="col-sm-3">';
    html+='<input type="text" class="form-control" placeholder="请输入" name="warnMin"  ngModel>';
    html+='</div>';
    html+='</div>';
    html+='<div class="row clearfix">';
    html+='<label class="col-sm-1 control-label">预警最大值：</label>';
    html+='<div class="col-sm-3">';
    html+='<input type="text" class="form-control" placeholder="请输入" name="warnMax"  ngModel>';
    html+='</div>';
    html+='<label class="col-sm-1 control-label">人工预警最小值：</label>';
    html+='<div class="col-sm-3">';
    html+='<input type="text" class="form-control" placeholder="请输入" name="manualMin"  ngModel>';
    html+='</div>';
    html+='</div>';
    html+='<div class="row clearfix">';
    html+='<label class="col-sm-1 control-label">人工预警最大值：</label>';
    html+='<div class="col-sm-3">';
    html+='<input type="text" class="form-control" placeholder="请输入" name="manualMax"  ngModel>';
    html+='</div>';
    html+='<label class="col-sm-1 control-label">量程上限：</label>';
    html+='<div class="col-sm-3">';
    html+='<input type="text" class="form-control" placeholder="请输入" name="rangeMax"  ngModel>';
    html+='</div>';
    html+='</div>';
    html+='<div class="row clearfix">';
    html+='<label class="col-sm-1 control-label">量程下限：</label>';
    html+='<div class="col-sm-3">';
    html+='<input type="text" class="form-control" placeholder="请输入" name="rangeMin"  ngModel>';
    html+='</div>';
    html+='<label class="col-sm-1 control-label">采样起始时间：</label>';
    html+='<div class="col-sm-3">';
    html+='<input type="text" class="form-control" placeholder="hhmmss" name="startTime"  ngModel>';
    html+='</div>';
    html+='</div>';
    html+='<div class="row clearfix">';
    html+='<label class="col-sm-1 control-label">采样周期(h)：</label>';
    html+='<div class="col-sm-3">';
    html+='<input type="text" class="form-control" placeholder="取值0~24" name="samplePeriod"  ngModel>';
    html+='</div>';
    html+='<label class="col-sm-1 control-label">出样时间(min)：</label>';
    html+='<div class="col-sm-3">';
    html+='<input type="text" class="form-control" placeholder="取值0~120" name="outTime"  ngModel>';
    html+='</div>';
    html+='</div>';
    html+= '</div>';
    codeData.append(html);
    let deleteData=$('.delete-data');
    deleteData.click(function () {
      $(this).parent().remove();
    });
  }
  addPortedit(){
    let codeData=$('#code-boxedit');
    let html='';
    html+=' <div class="form-group first-line clearfix col-md-12">';
    html+='<div class="delete-data" click="deleteData()"><img src="assets/img/deleteDoat.png" >删除</div>';
    html+='<div class="row clearfix">';
    html+='<label class="col-sm-1 control-label">检测因子：</label> ';
    html+='<div class="col-sm-1">';
    html+='<select class="form-control selectStyle " ngModel  name="pollutantCode" required>';
    html+='<option value="">请选择</option>';
    for(let i=0; i<this.dataCodeList.length;i++){
      html+='<option value='+this.dataCodeList[i]['code']+'>'+this.dataCodeList[i]['pollutantName']+'</option>';
    }
    html+='</select>';
    /*html+='<input type="text" class="form-control" placeholder="请输入" name="pollutantCode"  ngModel>';*/
    html+='</div> ';
    html+='<label class="col-sm-1 control-label">预警最小值：</label>';
    html+='<div class="col-sm-1">';
    html+='<input type="text" class="form-control" placeholder="请输入" name="warnMin"  ngModel>';
    html+='</div>';
    html+='<label class="col-sm-1 control-label">预警最大值：</label>';
    html+='<div class="col-sm-1">';
    html+='<input type="text" class="form-control" placeholder="请输入" name="warnMax"  ngModel>';
    html+='</div>';
    html+='</div>';
    html+='<div class="row clearfix">';
    html+='<label class="col-sm-1 control-label">人工预警最小值：</label>';
    html+='<div class="col-sm-1">';
    html+='<input type="text" class="form-control" placeholder="请输入" name="manualMin"  ngModel>';
    html+='</div>';
    html+='<label class="col-sm-1 control-label">人工预警最大值：</label>';
    html+='<div class="col-sm-1">';
    html+='<input type="text" class="form-control" placeholder="请输入" name="manualMax"  ngModel>';
    html+='</div>';
    html+='<label class="col-sm-1 control-label">量程上限：</label>';
    html+='<div class="col-sm-1">';
    html+='<input type="text" class="form-control" placeholder="请输入" name="rangeMax"  ngModel>';
    html+='</div>';
    html+='</div>';
    html+='<div class="row clearfix">';
    html+='<label class="col-sm-1 control-label">量程下限：</label>';
    html+='<div class="col-sm-1">';
    html+='<input type="text" class="form-control" placeholder="请输入" name="rangeMin"  ngModel>';
    html+='</div>';
    html+='<label class="col-sm-1 control-label">采样起始时间：</label>';
    html+='<div class="col-sm-1">';
    html+='<input type="text" class="form-control" placeholder="hhmmss" name="startTime"  ngModel>';
    html+='</div>';
    html+='<label class="col-sm-1 control-label">采样周期(h)：</label>';
    html+='<div class="col-sm-1">';
    html+='<input type="text" class="form-control" placeholder只有="单位为小时，取值0~24之间" name="samplePeriod"  ngModel>';
    html+='</div>';
    html+='</div>';
    html+='<div class="row clearfix">';
    html+='<label class="col-sm-1 control-label">出样时间：</label>';
    html+='<div class="col-sm-1">';
    html+='<input type="text" class="form-control" placeholder="单位为分钟，取值0~120之间" name="outTime"  ngModel>';
    // html+='<input type="hidden" class="form-control" placeholder="请输入" name="equipmentId"  [(ngModel)]="this.equipmentId">';
    html+='</div>';
    html+='</div>';
    html+= '</div>';
    codeData.append(html);
    let deleteData=$('.delete-data');
    deleteData.click(function () {
      $(this).parent().remove();
    });
  }
  queryAcqEquipmentList(){
    this.pointService.queryAcqEquipmentList(this.urldata)
      .subscribe(
        data => {
          this.queryAcqEquipment=data;
        });
  }
  doAddpointa(equipmentId){
    let arrayObj = new Array();
    let codebox = $("#code-box .first-line");
    $.each(codebox, function (item,i) {
      let obj = $(this).find("input");
      let objselect = $(this).find("select");
      let pollutantCode = objselect.eq(0).val(); //检测因子
      let warnMin = obj.eq(0).val();//预警最小值
      let warnMax = obj.eq(1).val();//预警最大值
      let manualMin = obj.eq(2).val();//人工预警最小值
      let manualMax = obj.eq(3).val();//人工预警最大值
      let rangeMax = obj.eq(4).val();//量程上限
      let rangeMin = obj.eq(5).val();//量程下限
      let startTime = obj.eq(6).val();//采样起始时间
      let samplePeriod = obj.eq(7).val();//采样周期(h)
      let outTime = obj.eq(8).val();//出样时间

      let objson = { "equipmentId": "" + equipmentId + "","pollutantCode": "" + pollutantCode + "", "warnMin": "" + warnMin + "", "warnMax": "" + warnMax + "", "manualMin": "" + manualMin + "", "manualMax": "" + manualMax + "", "rangeMax": "" + rangeMax + "", "rangeMin": "" + rangeMin + "", "startTime": "" + startTime + "", "samplePeriod": "" + samplePeriod + "", "outTime": "" + outTime + "" };
      arrayObj.push(objson);
    });
    let dataObj = JSON.stringify(arrayObj);
    this.pointService.createPoint(dataObj).subscribe(
      data => {
        if(data.resultCode=='0'){
          $("#addModal3").modal('hide');
          $('.selectStyle').val('');
          $("#code-box").html('');
          $("#add").modal('show');
          this.getLists();
          scrollTo(0,0);
        }else {
          this.errorMessage = "添加失败！";
          $("#error").modal('show');
        }

      });
  }
  //时间插件
  dateRangePicker(){
    let picker:any=$('.startEndTime');
    let dataRageOption:Object={
      singleDatePicker: true,
      "timePicker": true,
      "timePicker24Hour": true,
      "drops": "down",
      "opens": "left",
      "locale": {
        "format": "YYYY-MM-DD HH:mm:ss",
        "separator": " -- ",
        "applyLabel": "应用",
        "cancelLabel": "取消",
        "fromLabel": "From",
        "toLabel": "To",
        "customRangeLabel": "Custom",
        "daysOfWeek": [
          "日",
          "一",
          "二",
          "三",
          "四",
          "五",
          "六"
        ],
        "monthNames": [
          "一月",
          "二月",
          "三月",
          "四月",
          "五月",
          "六月",
          "7月",
          "八月",
          "九月",
          "十月",
          "十一月",
          "十二月"
        ],
        "firstDay": 1
      },
      "startDate": new Date(),
    };
    picker.daterangepicker(dataRageOption,function (start,end,label) {
      this.cTime=start.format('YYYY-MM-DD HH:mm:ss')
    });
  }
  ngOnInit() {
    this.route.queryParams.subscribe(params => {
      this.urldata = params['id'];
    });
    //获取分页信息
    this.getLists();
    this.areaList();
    this.getMonitor();
    this.getPort();
    this.dateRangePicker();
    this.getEquipment();
    this.getDataAcqList();
    this. getqueryEquipmentList();
    this.queryAcqEquipmentList();
  }
}
